package com.hll.api.config.web;

import com.hll.api.exception.MyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 接口异常处理，返回json
 *
 * @author 何龙
 * @create 2019-06-02 10:26
 */
@RestControllerAdvice
public class GlobalDefaultExceptionHandler {
    private static Logger log = LoggerFactory.getLogger( GlobalDefaultExceptionHandler.class );

    @ExceptionHandler(MyException.class)
    public RespMessage myExceptionHandler(MyException e) {
        return RespMessage.error( e.getStatus(), e.getMessage() );
    }

    @ExceptionHandler(Exception.class)
    public RespMessage exceptionHandler(Exception e) {
        return RespMessage.error( RespMessage.Status.ERROR, e.getMessage() );
    }
}
